package com.koi.system.config.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式参数校验
 * @author 大猫
 * @date 2021/12/28 14:04
 */
public class CheckUtils {

    /**
     * 验证是否符合手机号码工具类
     * true是手机号，false不是手机号
     * @author 大猫
     * @date 2021/12/28 14:05
     * @param phone
     * @return boolean
     */
    public static boolean checkMobile(String phone){
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        // 验证手机号
        String s2="^[1](([3|5|8][\\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\\d]{8}$";
        if(StringUtils.isNotBlank(phone)){
            p = Pattern.compile(s2);
            m = p.matcher(phone);
            b = m.matches();
        }
        return b;
    }

    /**
     * 验证是否符合邮箱工具类
     * true是邮箱，false不是邮箱
     * @author 大猫
     * @date 2021/12/28 14:05
     * @param email
     * @return boolean
     */
    public static boolean checkEmail(String email) {
        if (StringUtils.isEmpty(email)){
            return false;
        }
        String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p;
        Matcher m;
        p = Pattern.compile(regEx1);
        m = p.matcher(email);
        if (m.matches()){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(checkMobile("19699999999"));
        System.out.println(checkEmail("19699999999"));
    }
}
